package com.hnhegui.backend.platform.controller.system;

import com.hnhegui.backend.entity.Result;
import com.hnhegui.backend.platform.service.system.RestAuthService;
import com.hnhegui.backend.platform.vo.payment.request.LoginRequestVO;
import com.hnhegui.backend.platform.vo.payment.response.LoginResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证Controller
 */
@RestController
@RequestMapping("/rest/auth")
public class RestAuthController {

    @Autowired
    private RestAuthService authService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<LoginResponseVO> login(@Validated @RequestBody LoginRequestVO request) {
        LoginResponseVO response = authService.login(request);
        return Result.success(response);
    }

    /**
     * 用户登出
     */
    @PostMapping("/logout/{userId}")
    public Result<Void> logout(@PathVariable("userId") Long userId) {
        authService.logout(userId);
        return Result.success();
    }
}
